﻿using System;
using System.IO;
using System.Xml;

/*      DONE: constructor system by special file;
 *      TODO: constructor system for GeneTable in visual form;           
*/


namespace ClassLibrary
{
    /* class intented to save data about one real gene */
    public class Gene
    {
        public Locus locus;

        public int allele_type_id { set; get; }
        public int allele { set; get; }


        /* constructor */
        public Gene(Locus loc, int alle_type_id, int alle)
        {
            locus = loc;
            allele_type_id = alle_type_id;
            allele = alle;
        }       
    }


    /*  Description of alternative genes set */
    public class GeneType
    {
        public int allele_type_id { set; get; }
        public string name { set; get; }
        public int amount_alelles { set; get; }
    }


    /*  Gene table */
    public class GeneTable
    {
        public string path { set; get; }
        public string name { set; get; }

        public int gene_types_amount { set; get; }
        public GeneType[] gene_table;


        /* Constructor
         * Args: path to file where genes_categories with allels are described
         * Do: creates massive of data for genes
        */
        public GeneTable(string path_to_gene_table)
        {
            path = path_to_gene_table;

            // open XML file            
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(File.ReadAllText(path_to_gene_table));            

            // reading gene_table's attributes
            name = doc.DocumentElement.GetAttribute("Name");
            gene_types_amount = Convert.ToInt32(doc.DocumentElement.GetAttribute("GeneCategoriesAmount"));


            // reading all data about gene categories
            if (gene_types_amount != 0)
            {
                // reading "gene" node in "genes"
                gene_table = new GeneType[gene_types_amount];                
                int i =-1;
                foreach (XmlNode xml_node in doc.GetElementsByTagName("gene"))
                {
                    i++;
                    int allele_type_id = Convert.ToInt32(xml_node.Attributes[0].Value);

                    gene_table[i] = new GeneType();
                    gene_table[i].allele_type_id = Convert.ToInt32(xml_node.Attributes[0].Value);
                    gene_table[i].name = xml_node.Attributes[1].Value;
                    gene_table[i].amount_alelles = Convert.ToInt32(xml_node.Attributes[2].Value);
                }                
            }           
        }       
    }
}